package com.web.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.web.entity.HealthAssessment;
import com.web.mapper.HealthAssessmentMapper;
import com.web.service.HealthAssessmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class HealthAssessmentServiceImpl implements HealthAssessmentService {
    @Autowired
    private HealthAssessmentMapper healthAssessmentMapper;
    @Override
    public PageInfo<HealthAssessment> list(Integer page, Integer pageSize, HealthAssessment healthAssessment) {
        PageHelper.startPage(page, pageSize);
        PageInfo<HealthAssessment> pageInfo = new PageInfo<>(healthAssessmentMapper.list(healthAssessment));
        return pageInfo;
    }

    @Override
    public HealthAssessment findById(Integer assessmentId) {
        HealthAssessment healthAssessment = this.healthAssessmentMapper.findById(assessmentId);
        return healthAssessment;
    }

    @Override
    public void add(HealthAssessment healthAssessment) {
        healthAssessment.setCreateTime(LocalDateTime.now());
        healthAssessment.setUpdateTime(LocalDateTime.now());
        this.healthAssessmentMapper.add(healthAssessment);

    }

    @Override
    public void update(HealthAssessment healthAssessment) {
        healthAssessment.setUpdateTime(LocalDateTime.now());
        this.healthAssessmentMapper.update(healthAssessment);

    }

    @Override
    public void delete(Integer doctorId) {
        this.healthAssessmentMapper.delete(doctorId);

    }

    @Override
    public List<HealthAssessment> byUserId(Integer userId) {
        List<HealthAssessment> healthAssessment = this.healthAssessmentMapper.byUserId(userId);
        return healthAssessment;
    }

    @Override
    public HealthAssessment byDoctorId(Integer doctorId) {
        HealthAssessment healthAssessment = this.healthAssessmentMapper.byDoctorId(doctorId);
        return healthAssessment;
    }
}
